package sys.util;

import sys.database.Database;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class EventUtil {

    // OK
    public static String getNameOfEventByID(String eventID) {
        String sql = "select * from event where eventID = " + eventID;
        PreparedStatement preparedStatement = new Database().createConnection(sql);
        try {
            ResultSet res = preparedStatement.executeQuery();
            if (res.next()) {
                return res.getString("eventName");
            }
        } catch (SQLException e) {
            System.out.println("项目名称查找失败！");
        }
        return null;
    }

    public static void showEnvent(String eventID) {
        String sql = "select * from event where eventID = " + eventID;
        PreparedStatement preparedStatement = new Database().createConnection(sql);
        try {
            ResultSet res = preparedStatement.executeQuery();
            if (res.next()) {
                String id = res.getString("eventID");
                String name = res.getString("eventName");
                String place = res.getString("place");
                String rule = res.getString("rule");
                System.out.println(id + "\t\t" + name + "\t\t\t" + place + "\t\t\t" + rule);
            }
        } catch (SQLException e) {
            System.out.println("项目检索失败！");
        }
    }
}
